package it.polimi.TravelDream.ejb.eaos;

import it.polimi.TravelDream.ejb.dtos.AddressDTO;
import it.polimi.TravelDream.ejb.dtos.UserDTO;
import it.polimi.TravelDream.ejb.entities.Address;
import it.polimi.TravelDream.ejb.entities.User;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Session Bean implementation class UserEAO
 */
@Stateless
public class UserEAO implements UserList {

	@PersistenceContext
	private EntityManager em;
	
    /**
     * Default constructor. 
     */
    public UserEAO() {
    }
    
    @Override
    public void add(UserDTO userDTO, AddressDTO addressDTO){
    	User user = new User(userDTO);
    	Address address;
    	
    	address = new Address(addressDTO);
    	em.persist(user);
    	user.setAddress(address);
    	    	
    }

}
